#ifndef _vr_dragonball_
#define _vr_dragonball_

#include "vr.h"
#include "igslib_iserial_manager.h"
#include "protocol_DragonBall.h"

namespace igslib
{
    class vr_Grgn:public CVR
    { 
        protected:
            static int ID;
			int LocID;
        public:

            vr_Grgn()
            {
                ID++;
				LocID=ID;
            }
            ~vr_Grgn()
			{
				if(ID>-1)
				 ID--;
			}
            void SetSPI(ISpi* value) { spi = value; this->VRenable(); }		
            int GetPosition(float* result)
            {
                int rtn = 0;
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                rtn=tmp->GetVRabs(LocID,&now_pos);
                *result = now_pos;
				return rtn;
            }
			int GetOffset(float* result)
            {
                int rtn = 0;
                Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                float dtmp;
                rtn = tmp-> GetVRrela(LocID,&dtmp);
				if(dtmp>127)
				{
				  dtmp=256-dtmp;
				  dtmp*=-1;
				}
                *result = dtmp;
				return rtn;
            }
            void VRenable() 
            { 
                 Protocol_DragonBall* tmp = (Protocol_DragonBall*)(spi);
                 tmp->SetupVR(LocID,1);
            }	 

    };
    int vr_Grgn::ID = -1;
};

#endif


/*

	3288->MCU Initial									說明
	SPI_HeaderId			0x6			
	SPI_DataLength			3							SPI Data Length
	Data[0]					cmd	"0x00"					initial
	Data[1]					ID			
	Data[2]					Enable	1: on, 2: off		enable/disable
	SPI_DataChecksum						



*/
